layui.define(['table', 'form'], function(exports){
  var $ = layui.$, form = layui.form;
  
  $('#fileIconUrl').change(function(){
	  var file = this.files[0];
	  // 创建FormData对象
	  var formData = new FormData();
	  formData.append('file', file);
	  
	  // 发送ajax请求
	  var xhr = new XMLHttpRequest();
	  xhr.open('POST', layui.setter.webRoot + '/common/icon/img/upload.do', true);
	  xhr.responseType = 'json'
	  xhr.onreadystatechange = function() {
	    if (xhr.readyState === 4 && xhr.status === 200) {
	      // 上传成功的操作
	      console.log('图片上传成功！');
		  var res = xhr.response;
		  if(res.code == 200){
			$('input[name="iconUrl"]').val(res.body.path);
			$('#iconUrl').attr("src",res.body.imgUrl);
		  }
	    } else if (xhr.readyState === 4 && xhr.status !== 200) {
	      // 上传失败的操作
	      console.log('图片上传失败！');
	    }
	  };
	  xhr.send(formData);
  });
  
  $('#iconUrl').click(function(){
	$('#fileIconUrl').click();
  });
  
  exports('func_model_edit2', {})
});